﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace ProductKeyManager.UI
{
    /// <summary>
    /// LocalizableLabel is an extension of <see cref="System.Windows.Controls.Label"/> that accepts
    /// a resource key that will be used to load a resource out of localized resources.
    /// </summary>
    public class LocalizedLabel : System.Windows.Controls.Label
    {
        private string _ResourceKey;

        /// <summary>
        /// Gets or sets the resource key.
        /// </summary>
        /// <value>The resource key.</value>
        public string ResourceKey
        {
            get { return _ResourceKey; }
            set
            {
                _ResourceKey = value;
                this.Content = this.LoadStringResource(this.ResourceKey);
            }
        }

        /// <summary>
        /// Loads the string resource.
        /// </summary>
        /// <param name="resourceName">Name of the resource.</param>
        /// <returns>The localized version of the string with the specified resource name</returns>
        private string LoadStringResource(string resourceName)
        {
            return (string)Application.Current.FindResource(resourceName);
        }
    }
}
